package com.qiaotongtianxia.loans.views;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.qiaotongtianxia.loans.R;


/**
 * Created by lisen on 2017/11/10.
 *
 * @author lisen < 4533548588@qq.com >
 */

public class LoadingProgress extends BaseProgress{

    private Context context;

    private View view;

    private TextView tv_progressTip;

    private Dialog dialog;

    public LoadingProgress(Context context) {

        this.context = context;
        view = LayoutInflater.from(context).inflate(R.layout.loading_progress_dialog,null);
        tv_progressTip = (TextView) view.findViewById(R.id.tv_progressTip);
        dialog = new Dialog(context,R.style.Loading_Progress);
    }

    @Override
    public void setProgressTip(String tip) {
        tv_progressTip.setText(tip);
    }

    @Override
    public void show(){
        dialog.setContentView(view);
        dialog.setCancelable(false);
        dialog.show();
        // Dialog显示时背景不变暗
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.dimAmount = 0.3f;
        dialog.getWindow().setAttributes(lp);
    }

    @Override
    public void dismiss() {
        if (dialog != null && dialog.isShowing()){
            dialog.dismiss();
        }
    }

    public boolean isShowing(){
        if (dialog != null){
            return dialog.isShowing();
        }
        return false;
    }
}
